home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / tools / ebsx130 / gaiji2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-13  |  7.8 KB  |  380 lines

  1. /* EB.X V1.10 
  2.    1995.9.3 鈴木 健児 */
  3.  
  4. #include "common2.h"
  5.  
  6. #include <iocslib.h>
  7. #include <jctype.h>
  8. #include <method\Dos_i.h>
  9.  
  10. int    set_gaiji( int );
  11. int    set_gaiji2( int , unsigned int );
  12. int    set_gaiji1( int , unsigned int );
  13. int    reset_gaiji( void );
  14. int    set_gaiji_ebg( int , unsigned int );
  15. int    reset_gaiji_ebg( void );
  16. int    nextcode( int );
  17. int    nextcodejis( int );
  18.  
  19. extern int        cdfile;
  20.  
  21. int        codetbl1[ 190 ];
  22. int        codetbl2[ 190 ];
  23. int        codetblebg[ 258 ];
  24. unsigned short    f2jisst , f2jised , f2jismax;
  25. unsigned short    f1jisst , f1jised , f1jismax;
  26. unsigned short    f2ascst , f2asced , f2ascmax;
  27. unsigned char    f2esc;
  28. static    int    fnttblptr;
  29. static    unsigned int    f1pagenumber;        /* 全角外字 */
  30. static    unsigned int    f2pagenumber;        /* 半角外字 */
  31.  
  32. /* char    fn2[ ] = "j:\\crger\\start" ; */
  33. /* char    fn2[ ] = "f:\\fss\\start" ; */
  34. /* char    fn2[ ] = "j:\\jirin\\start" ; */
  35.  
  36. /*
  37. int main(int argc, char *argv[])
  38. {
  39.     unsigned short rootpagenumber;
  40.     int    code;
  41.  
  42.     cdfile = fopen( fn2 , "rb" );
  43.     if( cdfile == NULL)
  44.     {
  45.         printf( "Error ファイルがオープンできません\n" );
  46.         return( 0 );
  47.     };
  48.  
  49.  
  50.     rootpagenumber = search_rootindexpos2( 0xf200 );
  51.     if( rootpagenumber == 0 )
  52.     {
  53.         return( 0 );
  54.     };
  55.     DOSSEEK( cdfile , rootpagenumber*0x800 , SEEK_SET );
  56.     code = set_gaiji2( 0xeb9f );
  57.     printf( "\ncode2 = %x\n" , code );
  58.  
  59.     DOSSEEK( cdfile , 0 , SEEK_SET );
  60.     rootpagenumber = search_rootindexpos2( 0xf100 );
  61.     if( rootpagenumber == 0 )
  62.     {
  63.         return( 0 );
  64.     };
  65.     DOSSEEK( cdfile , rootpagenumber*0x800 , SEEK_SET );
  66.     code = set_gaiji1( code );
  67.     printf( "\ncode1 = %x\n" , code );
  68.  
  69.     return( 0 );
  70. }
  71. */
  72.  
  73. unsigned short    search_rootindexpos2( void )
  74. {
  75.     unsigned short saizu;
  76.     unsigned short data;
  77.     unsigned short retcode;
  78.     int i;
  79.  
  80.     DOSREAD( cdfile , &saizu , sizeof( unsigned short ) );    
  81.     DOSSEEK( cdfile , 16 , SEEK_SET );
  82.  
  83.     i = 0;
  84.     while( i < saizu )
  85.     {
  86.         DOSREAD( cdfile , &data , sizeof( unsigned short ) );    
  87.         if(( data & 0xff00 ) == 0xf200 )
  88.         {
  89.             DOSREAD( cdfile , &f2pagenumber , sizeof( unsigned int ) );
  90.             DOSSEEK( cdfile , 10 , SEEK_CUR );
  91.         }
  92.         else if(( data & 0xff00 ) == 0xf100 )
  93.         {
  94.             DOSREAD( cdfile , &f1pagenumber , sizeof( unsigned int ) );
  95.             DOSSEEK( cdfile , 10 , SEEK_CUR );
  96.         } else {
  97.             DOSSEEK( cdfile , 14 , SEEK_CUR );
  98.         };
  99.         i++;
  100.     };
  101.  
  102.     return( 0 );
  103. }
  104.  
  105.  
  106. int    set_gaiji( int limit )
  107. {
  108.     int    code;
  109.     int    i;
  110.  
  111.     search_rootindexpos2( );
  112.  
  113.     if( e_key == 0 )
  114.     {
  115.         code = 0xeb9f;
  116.         /* 半角外字の登録 */
  117.         /* 追加(95.10.03 M.Kamada) */
  118.         codetbl2[ 0 ] = 0xffff;
  119.         if( f2pagenumber != 0 )
  120.         {
  121.             code = set_gaiji2( code , f2pagenumber-1 );
  122.         };
  123.  
  124.         /* 全角外字の登録 */
  125.         /* 追加(95.10.03 M.Kamada) */
  126.         codetbl1[ 0 ] = 0xffff;
  127.         if( f1pagenumber != 0 )
  128.         {
  129.             code = set_gaiji1( code , f1pagenumber-1 );
  130.         };
  131.     } else {
  132.         code = 0xeb9f;
  133.         /* 半角外字の登録 */
  134.         /* 追加(95.10.03 M.Kamada) */
  135.         codetbl2[ 0 ] = 0xffff;
  136.         if( f2pagenumber != 0 )
  137.         {
  138.             code = set_gaiji_ebg( code , f2pagenumber-1 );
  139.         } else {
  140.             for( i=0; i<257; i++ )
  141.             {
  142.                 codetblebg[ i ] = 0xffff;
  143.             };
  144.         };
  145.     };
  146.  
  147.     return( 0 );
  148. }
  149.  
  150.  
  151. /* set_gaiji2()、set_gaiji1()の順でコールすること fnttblptrの関係 */
  152. /* 半角 f200 はこれで良いらしい 0xa121~に対応 */
  153. int    set_gaiji2( int code , unsigned int pagenum )
  154. {
  155.     int i , o , k , stat;
  156.     int count;
  157.     unsigned short numofgaiji;
  158.     unsigned char bitpatan;
  159.     unsigned char patan[ 32 ];
  160.  
  161.     DOSSEEK( cdfile , pagenum*0x800 , SEEK_SET );
  162.     DOSSEEK( cdfile , 10 , SEEK_CUR );
  163.     DOSREAD( cdfile , &f2jisst , sizeof( unsigned short ) );
  164.     DOSREAD( cdfile , &numofgaiji , sizeof( unsigned short ) );    
  165.  
  166.     /* 外字の終わりのコード(JIS)を得る */
  167.     f2jised = f2jisst;
  168.     for( count=0; count < (numofgaiji-1); count++ )
  169.     {
  170.         f2jised = nextcodejis( f2jised );
  171.     };
  172. /* printf( "gaiji = %4x , %4x , %d\n" , f2jisst , f2jised , numofgaiji ); */
  173.     f2jismax = f2jisst-1;
  174.  
  175.     DOSSEEK( cdfile , (pagenum+1)*0x800 , SEEK_SET );
  176.  
  177. /*    code = JISSFT( 0x7721 ); */
  178.     i = 0;
  179.  
  180.     for( count=0; count<numofgaiji; count++ )
  181.     {
  182.         codetbl2[ i ] = code;
  183.  
  184.         f2jismax = nextcodejis( f2jismax );
  185.         code = nextcode( code );
  186.         if( code == -1 )
  187.         {
  188.             count = numofgaiji;
  189.         };
  190.         i++;
  191.     };
  192.     codetbl2[ i ] = 0xffff;
  193.  
  194. /* printf( "gaijimax = %4x" , f2jismax ); */
  195.     fnttblptr = i;
  196.     return( code );
  197. }
  198.  
  199. /* set_gaiji2()、set_gaiji1()の順でコールすること fnttblptrの関係 */
  200. /* 全角 f100 はこれで良いらしい 0xa421~に対応する */
  201. int    set_gaiji1( int code , unsigned int pagenum )
  202. {
  203.     int i , o , k , stat;
  204.     int count;
  205.     unsigned short numofgaiji;
  206.     unsigned char bitpatan;
  207.     unsigned char patan[ 32 ];
  208.  
  209.     DOSSEEK( cdfile , pagenum*0x800 , SEEK_SET );
  210.     DOSSEEK( cdfile , 10 , SEEK_CUR );
  211.     DOSREAD( cdfile , &f1jisst , sizeof( unsigned short ) );    
  212.     DOSREAD( cdfile , &numofgaiji , sizeof( unsigned short ) );    
  213.  
  214.     /* 外字の終わりのコード(JIS)を得る */
  215.     f1jised = f1jisst;
  216.     for( count=0; count < (numofgaiji-1); count++ )
  217.     {
  218.         f1jised = nextcodejis( f1jised );
  219.     };
  220. /* printf( "gaiji = %4x , %4x , %d\n" , f1jisst , f1jised , numofgaiji ); */
  221.     f1jismax = f1jisst-1;
  222.     DOSSEEK( cdfile , (pagenum+1)*0x800 , SEEK_SET );
  223.  
  224.     if( code < 0 )
  225.     {
  226.         return( code );
  227.     };
  228.  
  229. /*    j = JISSFT( 0x7621 ); */
  230.  
  231.     i = 0;
  232.     for( count=0; count<numofgaiji; count++ )
  233.     {
  234.         codetbl1[ i ] = code;
  235.  
  236.         f1jismax = nextcodejis( f1jismax );
  237.         code = nextcode( code );
  238.         if( code == -1 )
  239.         {
  240.             count = numofgaiji;
  241.         };
  242.         i++;
  243.     };
  244.     codetbl1[ i ] = 0xffff;
  245. /* printf( "gaijimax = %4x" , f1jismax ); */
  246.  
  247.     return( code );
  248. }
  249.  
  250. int reset_gaiji( void )
  251. {
  252.     return( 0 );
  253. }
  254.  
  255. /* set_gaiji_ebg()、EBG形式の電子ブック用 */
  256. /* 半角 f200 */
  257. int    set_gaiji_ebg( int code , unsigned int pagenum )
  258. {
  259.     int i , j , o , k , stat , flg;
  260.     unsigned short numofgaiji;
  261.     unsigned char bitpatan;
  262.     unsigned char patan[ 32 ];
  263.  
  264.     DOSSEEK( cdfile , pagenum*0x800 , SEEK_SET );
  265.     DOSSEEK( cdfile , 10 , SEEK_CUR );
  266.     DOSREAD( cdfile , &f2ascst , sizeof( unsigned short ) );    
  267.     DOSREAD( cdfile , &numofgaiji , sizeof( unsigned short ) );    
  268.  
  269.     f2esc = ( f2ascst >> 8 );
  270.     f2ascst = ( f2ascst & 0x00ff );
  271.     /* 外字の終わりのコードを得る */
  272.     f2asced = f2ascst + numofgaiji;
  273.     if( f2asced > 255 )
  274.     {
  275.         f2asced = 255;
  276.     };
  277.  /* printf( "gaiji = %4x , %4x , %d\n" , f2ascst , f2asced , numofgaiji ); */
  278.     f2ascmax = f2ascst-1;
  279.     DOSSEEK( cdfile , (pagenum+1)*0x800 , SEEK_SET );
  280.  
  281. /*    code = JISSFT( 0x7721 ); */
  282.     i = 0;
  283.     for( j=f2ascst; j<=f2asced; j++ )
  284.     {
  285.         flg = 1;
  286.         for( o=0; o<16; o++ )
  287.         {
  288.             DOSREAD( cdfile , &bitpatan , sizeof( unsigned char ) );    
  289.             patan[ o*2   ] = bitpatan;
  290.             patan[ o*2+1 ] = 0;
  291.             if( bitpatan != 0 )
  292.             {
  293.                 flg = 0;
  294.             };
  295.         };
  296.         if( flg == 0 )
  297.         {
  298. /*    printf( "i=%x c=%4x %c%c : " , i , code , code >> 8 , code & 0x00ff ); */
  299.             codetblebg[ j ] = code;
  300.  
  301.             f2ascmax++;
  302.             code = nextcode( code );
  303.             if( code == -1 )
  304.             {
  305.                 flg = 1;
  306.                 puts( "外字の数が多すぎます\n" );
  307.             };
  308.             i++;
  309.         } else {
  310.             codetblebg[ j ] = 0xffff;
  311.         };
  312.     };
  313. /* printf( "gaijimax = %4x" , f2ascmax ); */
  314.  
  315.     return( code );
  316. }
  317.  
  318. int reset_gaiji_ebg( void )
  319. {
  320.     return( 0 );
  321. }
  322.  
  323. /* in sjis code */
  324. int    nextcode( int code )
  325. {
  326.     code++;
  327.     /* 0xebfd ~ 0xec3f をとばす */
  328.     if( code == 0xebfd  )
  329.     {
  330.         code = 0xec40;
  331.     };
  332.     /* 0xec7f をとばす */
  333.     if( code == 0xec7f  )
  334.     {
  335.         code++;
  336.     };
  337.     /* 外字エリアの範囲を越えた */
  338.     if( code > 0xec9e )
  339.     {
  340.         code = -1;
  341.     };
  342.  
  343.     return( code );
  344. }
  345.  
  346. int    nextcodejis( int code )
  347. {
  348.     code++;
  349.     if( ( code & 0x00ff ) == 0x7f ) 
  350.     {
  351.         code += (( 0x0121 - 0x007e )-1 ) ;
  352.     };
  353.  
  354.     return( code );
  355. }
  356.  
  357. /*
  358. void printdump( )
  359. {
  360.     int i , j ;
  361.     unsigned short data;
  362.     int sjis;
  363.     int ch,cl;
  364.  
  365.     for( i=0;i<128;i++)
  366.     {
  367.         printf( "%2d  "  , i );
  368.         for( j=0;j<8;j++)
  369.         {
  370.             DOSREAD( &data , sizeof( unsigned short ) , 1 , cdfile );
  371.             sjis = JISSFT( data );
  372.             ch = ( sjis & 0xff00 ) >> 8;
  373.             cl = sjis & 0x00ff ;
  374.             printf( "%4x:%c%c " , data , ch , cl );
  375.         };
  376.         printf( "\n" );
  377.     };
  378. }
  379. */
  380.